/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!		\file		prpex_integer.h
  \date		june 2011
  \author		TNick

  \brief		integer class


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read ReadMe.txt and Licence.txt in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PRPEX_INTEGER_INC__
#define __PRPEX_INTEGER_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<limits>
#include	<QString>
#include	"prpmdl.h"
#include	"prptpl.h"

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/// class representing a integer
/**
*	integers are diffrent from all other types; they are hosting subitems
*	and are the only type allowed at top level
*/
class PEX_Int : public PrpTpl		{

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:

	/// this is the value of this item
	int			int_value;

	/// lower limit; this value is "last" legal value
	int			int_low;

	/// higher limit; this value is "top" legal value
	int			int_high;

	/// step; ammount by which value is incremented / decremented
	int			int_step;

	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:

	/// constructor;
	PEX_Int		(
		PrpMdl*		pa_mdl,		/**< father model */
		PrpNode*	pa_fth,		/**< father item; NULL for top level */
		QString		stra_name,	/**< name of entry */
		QString		stra_descr,	/**< description of entry */
		int			inta_init	/**< initial value */
		) : PrpTpl(pa_mdl,pa_fth,PrpTpl::INTEGER,stra_name,stra_descr)
	{
			int_value = inta_init;
			int_low = std::numeric_limits<int>::min();
			int_high = std::numeric_limits<int>::max();
			int_step = 1;
	}

	/// destructor;
	virtual				~PEX_Int		(void) {}

	/// request actual value in text form
	virtual QVariant		valAsText	(void)
	{	return QString("%1").arg(int_value); }
	/// request decoration for the value
	virtual	QVariant		valAsDecor	(void)
	{	return QVariant(); }
	/// request to change the value made by user
	virtual bool			changeVal	(QVariant new_value);
	/// create editor for this type of item
	virtual	QWidget*	editCreate	(
		QWidget *					parent,
		const QStyleOptionViewItem	&option
		);
	/// load data from item to editor
	virtual	void		editLoad	(
		QWidget *					editor
		);
	/// save data from editor to item
	virtual	void		editSave	(
		QWidget *					editor
		);
//	/// update geometry for the editor
//	virtual	void		editResize	(
//		QWidget *					editor,
//		const QStyleOptionViewItem	&option
//		);

	/// tell what is the lower limit
	inline int		lowLimit	(void)
	{ return int_low; }
	/// set the lower limit
	inline void			setLowLimit	(int int_new_low)
	{ int_low = int_new_low; }


	/// tell what is the higher limit
	inline int		highLimit	(void)
	{ return int_high; }
	/// set the higher limit
	inline void			sethighLimit(int int_new_high)
	{ int_high = int_new_high; }

	/// set both limits in one go
	inline void			setLimits	(
			int int_new_low, int int_new_high)
	{ int_low = int_new_low;
	  int_high = int_new_high; }


	/// tell what is the step
	inline int		step	(void)
	{ return int_step; }
	/// set the step
	inline void			setStep	(int int_new_step)
	{ int_step = int_new_step; }


	inline int			value		(void)
		{ return int_value; }
	inline void			setValue	(int i_new_value)
		{ int_value = i_new_value; }



	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class PEX_Int	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __PRPEX_INTEGER_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
